package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Room;
import common.base.BaseServlet;
import service.RoomService;
import service.impl.RoomServiceImpl;



/**
 * Servlet implementation class RoomServlet
 */
@WebServlet("/RoomServlet")
public class RoomServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    
	public String ui(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		//接受商品的id
		String rid = request.getParameter("rid");
		//根据商品id，查询商品信息
		RoomService roomService = new RoomServiceImpl();
		Room room = roomService.queryRoomById(rid);
		
		//将商品放入请求域
		request.setAttribute("room", room);
		
		return "/user/room.jsp";
	}

	//根据商品名称模糊查询
	public String queryByName(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//获得查询的商品名称
		String rname = request.getParameter("rname");
		
		//通过业务层实现模糊查询
		RoomService roomService =
				new RoomServiceImpl();
		List<Room> rooms = roomService.queryByName(rname);
		
		//想域中添加数据
		request.getSession().setAttribute("rooms", rooms);
		
		//跳转画面，直接跳转到Servlet？重定向？
		response.sendRedirect(request.getContextPath() + "/RoomServlet?action=roomListUi");
		
		//进入某个画面
		return null;
	}
	
	//显示商品一览的ui
	public String roomListUi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		return "/user/roomList.jsp";
	}
	
	
	//根据类别查询
	public String queryByType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String typeId = request.getParameter("typeId");
		
		//通过业务层查询该分类的房间列表
		RoomService roomService = new RoomServiceImpl();
		List<Room> rooms = roomService.queryByType(typeId);

		//想域中添加数据
		request.getSession().setAttribute("rooms", rooms);
		
		//跳转画面，直接跳转到Servlet？重定向？
		response.sendRedirect(request.getContextPath() + "/RoomServlet?action=roomListUi");
		
		return "";
	}
	
	

}
